package dp;

import java.util.Arrays;
import java.util.Scanner;

public class multiBag {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int c = scanner.nextInt();
        int n = scanner.nextInt();
        int[] w = new int[n];
        int[] v = new int[n];
        int[] k = new int[n];
        for (int i = 0; i < n; i++) {
            w[i] = scanner.nextInt();
        }
        for (int i = 0; i < n; i++) {
            v[i] = scanner.nextInt();
        }
        for (int i = 0; i < n; i++) {
            k[i] = scanner.nextInt();
        }
        int sum = Arrays.stream(k).sum();
        int[] newW = new int[sum];
        int[] newV = new int[sum];
        int index = 0;
        for (int i = 0; i < k.length; i++) {
            for (int j = 0; j < k[i]; j++) {
                newW[index] = w[i];
                newV[index] = v[i];
                index++;
            }
        }
        int[] dp = new int[c + 1];
        dp[0] = 0;
        for (int i = 0; i < newW.length; i++) {
            for (int j = c; j >= newW[i]; j--) {
                dp[j] = Math.max(dp[j], dp[j - newW[i]] + newV[i]);
            }
        }
        System.out.println(dp[c]);
    }
}
